#include <iostream>
//#include <Windows.h>
//#include <unistd.h>
#include "ai.h"
//#include "gameboard.h"

int main()
{
	Gameboard game;
	game.setup();
	char color;
	char ai_color;
	char r;
	char c;
	char selected_difficulty;
	int row;
	int column;
	bool valid;
	bool black = true;
	int ipip=0;
	cout << "Grand Master Abhay's REVERSI!" << endl
		 << "O = White" << endl
		 << "@ = Black" << endl
		 << "* = Availble moves" << endl << endl
		 << "Black goes first" << endl
		 << "Choose your color: " << endl
		 << "\t 1)Black" << endl
		 << "\t 2)White" << endl;
	cin >> color;
	
	switch(color)
	{
		case '1': 
			ai_color = 'O';
			break;
		case '2':
			ai_color = '@';
			break;
		default:
			cout << "Sorry that isn't an option" << endl;
			break;
	}

	cout << "Choose difficulty: "<< endl
		 << "\t 1) Easy "<< endl
		 << "\t 2) Medium" << endl
		 << "\t 3) Hard" << endl;
		 
	cin >> selected_difficulty;
	
	game.showNextPos();
	game.display();
	

	while (true)
	{
		ipip=0;
		AIengine test1;
		AIengine test;
		while(game.currentColor() == ai_color)
		{
			cout << game.currentColor() << "'s turn" << endl << endl;
			cout << endl << "AI IS THINKING..." << endl;
			test.difficulty_of_the_AI(selected_difficulty,game);
				//Sleep(100);
				game.move((int)test.row,(int)test.column);
				game.showNextPos();
				game.display();
				ipip=test.count_num_moves(game);

			
		}
		
		valid = true;
		while(valid)
		{
			cout << game.currentColor() << "'s turn" << endl << endl;
			cout << "type 'u' in row to undo last move" << endl;
			cout << "row: ";
			cin >> r;
			switch(r)
			{
				case '1':
					row = 1;
					valid = false;
					break;
				case '2':
					row = 2;
					valid = false;
					break;
				case '3':
					row = 3;
					valid = false;
					break;
				case '4':
					row = 4;
					valid = false;
					break;
				case '5':
					row = 5;
					valid = false;
					break;
				case '6':
					row = 6;
					valid = false;
					break;
				case '7':
					row = 7;
					valid = false;
					break;
				case '8':
					row = 8;
					valid = false;
					break;
				case 'u':
					game.undo();
					game.showNextPos();
					game.display();
					break;
				default:
					cout << "Sorry that isn't an available row" << endl;
					break;
			}
		}

		valid = true;

		while(valid)
		{
			cout << "column: ";
			cin >> r;
			switch(r)
			{
				case 'a':
					column = 1;
					valid = false;
					break;
				case 'b':
					column = 2;
					valid = false;
					break;
				case 'c':
					column = 3;
					valid = false;
					break;
				case 'd':
					column = 4;
					valid = false;
					break;
				case 'e':
					column = 5;
					valid = false;
					break;
				case 'f':
					column = 6;
					valid = false;
					break;
				case 'g':
					column = 7;
					valid = false;
					break;
				case 'h':
					column = 8;
					valid = false;
					break;
				default:
					cout << "Sorry that isn't an available row" << endl;
					break;
			}
		}

		game.move(row,column);
		game.showNextPos();
		ipip=ipip+game.count_num_moves();
		
		if(ipip==0)
			game.gameOver();
	}	
}
